﻿using CL.Business.BLL;
using CL.Enum.Common;
using CL.Tools.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CL.Admin.admin.promotion
{
    public partial class Commission__rebate :UI.AdminPage
    {
        protected int totalCount;
        protected int page;
        protected int pageSize;
        protected string searchKey;
        protected void Page_Load(object sender, EventArgs e)
        {
            this.pageSize = GetPageSize(10); //每页数量
            if (!IsPostBack)
            {
                RptBind();
            }
        }

        //protected void btnDelete_Click(object sender, EventArgs e)
        //{
        //    ChkAdminLevel("Commission__rebate", CaileEnums.ActionEnum.Delete.ToString()); //检查权限
        //    int sucCount = 0;
        //    int errorCount = 0;
        //    RebateBLL bll = new RebateBLL();
        //    for (int i = 0; i < rptList.Items.Count; i++)
        //    {
        //        int id = Convert.ToInt32(((HiddenField)rptList.Items[i].FindControl("hidId")).Value);
        //        CheckBox cb = (CheckBox)rptList.Items[i].FindControl("chkId");
        //        if (cb.Checked)
        //        {
        //            if (bll.DelEntity(id))
        //            {
        //                sucCount += 1;
        //            }
        //            else
        //            {
        //                errorCount += 1;
        //            }
        //        }
        //    }
        //    AddAdminLog(CaileEnums.ActionEnum.Delete.ToString(), "删除代理返点设置" + sucCount + "条，失败" + errorCount + "条"); //记录日志
        //    JscriptMsg("删除成功" + sucCount + "条，失败" + errorCount + "条！", "Commission_rebate.aspx");
        //}

        private void RptBind()
        {
            this.page = QPRequest.GetQueryInt("page", 1);
            searchKey = QPRequest.GetQueryString("searchkey");
            RebateBLL bll = new RebateBLL();
            this.rptList.DataSource = bll.QueryListByPage(this.pageSize, this.page, searchKey, ref this.totalCount);
            this.rptList.DataBind();

            //绑定页码
            txtPageNum.Text = this.pageSize.ToString();
            string pageUrl = Utils.CombUrlTxt("Commission_rebate.aspx", "page={0}&searchkey={1}", "__id__", searchKey);
            PageContent.InnerHtml = Utils.OutPageList(this.pageSize, this.page, this.totalCount, pageUrl, 8);
        }


        #region 返回每页数量=============================
        private int GetPageSize(int _default_size)
        {
            int _pagesize;
            if (int.TryParse(Utils.GetCookie("Commission_rebate_page_size", "QPcmsPage"), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    return _pagesize;
                }
            }
            return _default_size;
        }


        #endregion

        protected void txtPageNum_TextChanged(object sender, EventArgs e)
        {
            int _pagesize;
            if (int.TryParse(txtPageNum.Text.Trim(), out _pagesize))
            {
                if (_pagesize > 0)
                {
                    Utils.WriteCookie("Commission_rebate_page_size", "QPcmsPage", _pagesize.ToString(), 14400);
                }
            }
            Response.Redirect("Commission_rebate.aspx");
        }
    }
}